package com.rtti;


import java.util.Objects;

/**
 * @program: study
 * @className: ListStack
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-12-04 17:03
 * @version: v1.0
 **/
public class ListStack<T> {

    /**
     * 栈顶元素
     */
    private Node<T> top = new Node<>();

    /**
     * 功能描述: 压入元素
     *
     * @param:
     * @return:
     * @auther: kukuxiahuni
     * @date: 2019/12/4 5:06 下午
     * @modify_auther: kukuxiahuni
     * @modify_time: 2019/12/4 5:06 下午
     **/
    public void push(T item) {
        top = new Node<>(item, this.top);
    }

    public T pop() {
        T result = this.top.item;
        if (!top.end()) {
            top = top.next;
        }

        return result;
    }

    /**
     * 功能描述: 列表中的节点
     *
     * @param:
     * @return:
     * @auther: kukuxiahuni
     * @date: 2019/12/4 5:04 下午
     * @modify_auther: kukuxiahuni
     * @modify_time: 2019/12/4 5:04 下午
     **/
    private final static class Node<U> {

        U item;
        Node<U> next;

        public Node() {
        }

        public Node(U item, Node<U> next) {
            this.item = item;
            this.next = next;
        }

        boolean end() {
            return Objects.isNull(item) && Objects.isNull(next);
        }
    }


}
